<template>
    <div>
        <el-row>
            <el-col :span="24" class="base-mian-cell"  v-if="healthFlag">
                <div class="base-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">体检报告一览</span>
                    </div>
                    <div class="right fr" @click="changeView">
                        <i class="el-icon-circle-close"></i>
                    </div>
                </div>
                <div class="check-main">
                    <button class="check-info" v-if="medicals.length>0" @click="showImageList">查看详情</button>
                </div>
                <div class="base-mian-cell-main">
                    <el-table
                            :data="medicals"
                            style="width: 100%"
                            @selection-change="handleSelectionChange">
                        <el-table-column
                                type="selection"
                                width="55">
                        </el-table-column>
                        <el-table-column prop="policyNo" label="保单号" min-width="120" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column  prop="docTyp" label="单证名称" min-width="120" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column prop="scanDate" label="扫描日期" min-width="160" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column prop="busiType" label="资料归属" min-width="120" show-overflow-tooltip>
                            <template slot-scope="scope">
                                {{scope.row.busiType | busiTypePipe}}
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-col>
        </el-row>
        <el-row>
            <!-- <el-col :span="24">
                <div class="pagination">
                    <el-pagination
                            background
                            v-if='paginations.total > 0'
                            :page-sizes="paginations.pageSizes"
                            :page-size="paginations.pageSize"
                            :layout="paginations.layout"
                            :total="paginations.total"
                            :current-page='paginations.pageIndex'
                            @current-change='handleCurrentChange'
                            @size-change='handleSizeChange'>
                    </el-pagination>
                </div>
            </el-col> -->
        </el-row>

        <!--影像列表-->
        <cdfs-image-list :drawer="showImageFlag" :policyNO="showImagePolicy" :docType="docType" @close="hideImageList"></cdfs-image-list>

    </div>
</template>
<script>
  import {busiTypePipe} from '@/pipe/comPipe';
  import CdfsImageList from "@/page/common/cdfsImageList";
  import {
    findExamReport
  } from "@/api/underwriting/uw";
  import constant from '@/utils/constant';
  import uwLoadJs from '@/utils/uwLoad';
  import appName from '@/api/appName';
  import {ImageQuerySearch} from "@/api/taskCenter/taskCommon";
export default {
    data(){
        return{
            claimData: [],
          medicals: [],
          multipleSelection:[],
          showImageFlag:false,
          showImagePolicy:'',
          docType:'体检报告单',
          paginations: {
            total: 0,        // 总数
            pageIndex: 1,  // 当前位于哪页
            pageSize: 100,   // 1页显示多少条
            pageSizes: [5, 10, 15, 20],  //每页显示多少条
            layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
          },

            initDataTimeOut:null
        }
    },
    props:{
        healthFlag:{
            type: Boolean,
            default: false
        },
      clntnum:{
        type: String,
        default: ""
      }
    },
  components: {
    "cdfs-image-list":CdfsImageList
  },
    destroyed() {
        clearTimeout(this.initDataTimeOut)
    },
    methods:{
        changeView(){
            this.$emit('subHealthFlag',false);
        },
      // handleCurrentChange(page) {
      //   this.paginations.pageIndex = page;
      //   this.initData();
      // },
      // handleSizeChange() {
      //   this.paginations.pageSize = pageSize;
      //   this.initData();
      // },
      initData(){
          debugger
        let that = this;
        let userId = "";
        let clntnum = this.clntnum;
        let pageSize = that.paginations.pageSize;
        let pageIndex = that.paginations.pageIndex;
        if(sessionStorage.getItem("loginForm")){
          let loginForm = JSON.parse(sessionStorage.getItem("loginForm"));
          userId=loginForm.userName;
        }

        that.$emit('showLoading',true);
        this.initDataTimeOut = setTimeout(function () {
          let policyNos="";
          let params = {
            "clntnum":clntnum
          }
          let url = appName.NEWUNDR + '/unipnd/euab/getChdrnumByClntnum';
          let res = uwLoadJs.ajaxRequest(params,url);
          if(res==null){

          }else if(res.data!=null){
            if(res.data.length>0){
              res.data.forEach(item=>{
                policyNos = policyNos +item+",";
              })
            }
            if(policyNos.indexOf(",")!=-1){
              policyNos = policyNos.substring(0,policyNos.length-1);
            }
          }
          that.medicals = [];
          if(policyNos!=""){
            let doctype = "体检报告单,`体检报告单,门诊病历,其他病历资料,`门诊病历,`其他病历资料,病历资料,承保后调查报告";
            let docType = doctype
            let params1 = {
              "begintime": "",
              "birthday": "",
              "branchCode": "",
              "busiNO":  "",
              "busiType": "NB",
              "comCode": "",
              "docType": docType,
              "doflag": "caseimage",
              "groupNO": "",
              "imgsort": "",
              "imgsortorder1": "",
              "imgsortorder2": "",
              "imgsortorder3": "",
              "insured": "",
              "isNoCaseno": "",
              "isPrint": "",
              "policyer": "",
              "policyNO": policyNos ? policyNos : "",
              "policyno16": "",
              "productType": "",
              "serno": "",
              "stockID": "",
              "sproductType": "",
              "spurview": "query",
              "stype": "general"
            }
            ImageQuerySearch(params1, userId, 1000, 1).then(res => {
              that.$emit('showLoading',false);
              if (res.resultCode == constant.SUCCESS && res.resBody) {
                if (res.strDoFlag == "image" || res.strDoFlag == "caseimage") {
                  for (var i = 0; i < res.resBody.imageList.length; i++) {
                    const obj = {
                      serno: res.resBody.imageList[i].serno,
                      docTyp: res.resBody.imageList[i].docTyp,
                      stockID: res.resBody.imageList[i].stockID,
                      groupNo: res.resBody.imageList[i].groupNo,
                      scanDate: res.resBody.imageList[i].scanDate,
                      scanTime: res.resBody.imageList[i].scanTime,
                      subbusitype: res.resBody.imageList[i].subbusitype,
                      isPrint: res.resBody.imageList[i].isPrint,
                      remark: res.resBody.imageList[i].remark,
                      busiType: res.resBody.imageList[i].busiType,
                      itemid: res.resBody.imageList[i].itemid,
                      policyNo: res.resBody.imageList[i].policyNo,
                      busiNo: res.resBody.imageList[i].busiNo,
                      productType: res.resBody.imageList[i].productType,
                      ishcprint: res.resBody.imageList[i].ishcprint,
                      version: res.resBody.imageList[i].version,
                      agentNo: res.resBody.imageList[i].agentNo,
                      updateflag: res.resBody.imageList[i].updateflag
                    }
                    that.medicals.push(obj);
                  }
                  this.paginations.total = res.resBody.total;
                }
              }
            }).catch(err => {

            })
          }
          that.$emit('showLoading',false);
        },100)
      },
      showImageList() {
          debugger
        if(this.multipleSelection.length>0){
          let applnum = "";
          let docType = "";
          this.multipleSelection.forEach(item=>{
            if(docType.indexOf(item.docTyp)==-1){
              docType = docType+item.docTyp+",";
            }
            applnum = applnum+item.policyNo+",";
          })
          if(docType.indexOf(",")!=-1){
            docType = docType.substring(0,docType.length-1);
            applnum = applnum.substring(0,applnum.length-1);
          }
          this.docType = docType;
          this.showImagePolicy = applnum;
          this.showImageFlag = true;
        }else{
          this.$message({
            message: "请选择需要查看的保单！",
            type: 'error'
          });
        }

      },
      hideImageList() {
        this.showImagePolicy = '';
        this.showImageFlag = false;
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      }
    },
  created(){
    this.initData();
  },
   filters:{
     busiTypePipe(value){
       return busiTypePipe(value);
     }
   }
}
</script>
<style lang="less" scoped>

</style>